package com.pyb.config;

import jakarta.servlet.Filter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

/**
 * Spring Web应用初始化器，用于配置Spring和SpringMVC上下文以及DispatcherServlet映射
 */
public class EpidemicApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    private static final Logger logger = LoggerFactory.getLogger(EpidemicApplicationInitializer.class);

    /**
     * 用来配置ContextLoaderListener创建对应上下文的bean
     */
    @Override
    protected Class<?>[] getRootConfigClasses() {
        logger.info("Loading root configuration classes.");
        return new Class[]{SpringConfig.class};
    }

    /**
     * 用于定义DispatcherServlet应用上下文的bean
     */
    @Override
    protected Class<?>[] getServletConfigClasses() {
        logger.info("Loading servlet configuration classes.");
        return new Class[]{SpringMVCConfig.class};
    }

    /**
     * 配置拦截器，将所有请求映射到DispatcherServlet
     */
    @Override
    protected String[] getServletMappings() {
        logger.info("Mapping all requests to DispatcherServlet.");
        return new String[]{"/"};
    }
}